package com.project.internship.controller.system;

import com.project.internship.entity.Class;
import com.project.internship.entity.Major;
import com.project.internship.entity.resp.RespBean;
import com.project.internship.service.ClassService;
import com.project.internship.service.MajorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/major_class")
public class SystemMajorClassController {

    @Autowired
    MajorService majorService;
    @Autowired
    ClassService classService;

    @GetMapping("/majors")
    public List<Major> getMajors(){
        return majorService.getMajors();
    }

    @GetMapping("/classes/{requiredId}")
    public List<Class> getAllClasses(@PathVariable("requiredId") Integer requiredId) {
        return classService.getAllClasses(requiredId);
    }

    @PostMapping("/major/")
    public RespBean addMajor(@RequestBody Major major) {
        if(majorService.addMajor(major) == 1) {
            return RespBean.ok("添加成功！");
        }
        return RespBean.error("添加失败！");
    }

    @DeleteMapping("/major/")
    public RespBean deleteMajor(@RequestBody Major major) {
        if(majorService.deleteMajor(major) == 1) {
            return RespBean.ok("删除成功！");
        }
        return RespBean.error("删除失败！");
    }

    @PostMapping("/class/")
    public RespBean addClass(@RequestBody Class aClass) {
        if(classService.addClass(aClass) == 1) {
            return RespBean.ok("添加成功！");
        }
        return RespBean.error("添加失败！");
    }

    @DeleteMapping("/class/{id}")
    public RespBean deleteClass(@PathVariable("id") Integer id) {
        if(classService.deleteClass(id) == 1) {
            return RespBean.ok("删除成功！");
        }
        return RespBean.error("删除失败！");
    }

}
